package cn.edu.hbwe.book.admin.servlet.books;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.hbwe.book.admin.service.books.BooksService;
import cn.edu.hbwe.book.entity.Book;

/**
 * Servlet implementation class FindBookConditionServlet
 */
public class FindBookConditionServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		// 获取查询条件
		String id = request.getParameter("id");
		String name = request.getParameter("name");
		String category = request.getParameter("category");
		String minprice = request.getParameter("minprice");
		String maxprice = request.getParameter("maxprice");
		// 创建service对象
		BooksService service = new BooksService();
		List<Book> lb = service.findBookCondition(id, name, category, minprice, maxprice);
		// 将商品信息保存到域对象
		request.setAttribute("lb", lb);

		request.getRequestDispatcher("/admin/books/list.jsp").forward(request, response);;
	}

}
